<?php


# Created on: 2011-12-10 23:36:20 616

/**
* Edit an entity in [ sizes ]
*/

$sizes = new sizes();

# Handle Editing, when data is supplied
if($variable->post('edit-action', 'string', '') && ($size_id = $variable->post('size_id', 'integer', 0)))
{
	# Editing....
	$code = $variable->post('protection_code', 'string', '');
	$data = $variable->post('sizes', 'array', array());
	
	# Mark when this data was modified last time.
	$data['modified_on'] = 'UNIX_TIMESTAMP(CURRENT_TIMESTAMP())';
	$data['modified_counter'] = 'modified_counter+1';
	$data['allowed_bytes'] = (int)$data['allowed_bytes'];
	
	if($success = $sizes->edit(
		$data, # Posted data
		array(
			'size_id' => $size_id,
		),
		$code, # Security code related to this entry
		$size_id
	))
	{
		$messenger = new messenger('success', 'The record has been modified.');
		
		stopper::url(url::last_page('sizes-list.php?context=permissions'));
	}
	else
	{
		stopper::url('sizes-edit-error.php');
	}
}
else
{
	/**
	* Otherwise, load the details of the entity before editing it.
	*/
	if($size_id = $variable->get('id', 'integer', 0))
	{
		$details = $sizes->details($size_id);
		if(!$details)
		{
			# Data about this entity was not available
			stopper::url('sizes-edit-error.php?context=data');
		}
		# Purpose of this code block is to make sure that the variable
		# gets all indices with blank data, to feed to EDIT form.
		$details = $sizes->validate('edit', $details);

		/**
		* Build Smarty Variable with FULL details
		*/
		$smarty->assign('sizes', $details);
	}
	else
	{
		# Really Bad...
		stopper::url('sizes-direct-access-error.php');
	}
}
?>